/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mypack;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.annotation.Resource;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.sql.DataSource;

/**
 *
 * @author iie
 */
@WebService(serviceName = "myaccount")
public class myaccount {

    @Resource(name = "data1")
    private DataSource data1;

    /**
     * Web service operation
     */
    @WebMethod(operationName = "insert")
    public String insert(@WebParam(name = "id") int id,
            @WebParam(name = "imie") String imie,
            @WebParam(name = "nazwisko") String nazwisko,
            @WebParam(name = "adres") String adres,
            @WebParam(name = "miasto") String miasto,
            @WebParam(name = "kod_pocztowy") String kod_pocztowy,
            @WebParam(name = "pesel") String pesel,
            @WebParam(name = "karta_choroby") int karta_choroby,
            @WebParam(name = "telefon") String telefon,
            @WebParam(name = "login") String login,
            @WebParam(name = "haslo") String haslo) {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/nfz", "root", "");
            PreparedStatement st = con.prepareStatement("insert into klienci values(?,?,?,?,?,?,?,?,?,?,?)");
            st.setInt(1, id);
            st.setString(2, imie);
            st.setString(3, nazwisko);
            st.setString(4, adres);
            st.setString(5, miasto);
            st.setString(6, kod_pocztowy);
            st.setString(7, pesel);
            st.setInt(8, karta_choroby);
            st.setString(9, telefon);
            st.setString(10, login);
            st.setString(11, haslo);
            st.executeUpdate();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return "record inserted";
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "select")
    public String select_logowanie(@WebParam(name = "username") String username, @WebParam(name = "password") String password)  {

        PreparedStatement st = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/nfz", "root", "");
            st = con.prepareStatement("select imie, nazwisko,login, haslo from klienci where login = ? and  haslo= ?");
            st.setString(1, username);
            st.setString(2, password);
            st.execute();
           
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return st.toString();
    }
}
